<template>
  <div class="article">
    <div
      class="item"
      v-for="item in list"
      :key="item.id"
      @click="$router.push('/detail?id=' + item.id)"
    >
      <div class="top">
        <!-- <div class="left">1</div> -->
        <img :src="item.avatar" alt="" />

        <div class="right">
          <div class="title">{{ item.stem }}</div>
          <div class="username">
            <span>{{ item.creator }}</span>
            <span> | </span>
            <span>{{ item.createdAt }}</span>
          </div>
        </div>
      </div>

      <div class="middle">
        {{ item.content }}
      </div>
      <div class="bottom">
        <span>点赞 {{ item.likeCount }}</span>
        <span> | </span>
        <span>浏览 {{ item.views }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      list: [],
    };
  },
  name: "HmArticle",
  created() {
    console.log("11");
    this.getlist();
  },
  // activated() {
  //   alert("激活显示时候触发");
  // },
  // deactivated() {
  //   alert("隐藏时候触发");
  // },
  methods: {
    async getlist() {
      const token = localStorage.getItem("token");
      // console.log("我是token", token);
      // console.log("22");
      const res = await axios({
        url: "http://interview-api-t.itheima.net/h5/interview/query",
        headers: {
          Authorization: `Bearer ${token}`,
        },
      });
      console.log(res);
      this.list = res.data.data.rows;
    },
  },
};
</script>

<style lang="less" scoped>
.item {
  padding: 10px;
  margin: 10px;
  border-bottom: 1px solid #999999;
  .top {
    display: flex;
    margin-bottom: 20px;

    img {
      width: 80px;
      height: 80px;
      border-radius: 50%;
      margin-right: 10px;
    }
    .title {
      // background-color: yellow;
      margin-top: 10px;
      font-size: 25px;
      margin-bottom: 6px;
    }
    .right {
      flex: 1;
      // background-color: pink;

      .username {
        color: #a0a0a0;
        font-size: 20px;
      }
    }
  }
}
// 超过两行显示省略号
.middle {
  margin-bottom: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-size: 28px;
}
.bottom {
  color: #a3a3a3;
  font-size: 28px;
}
</style>
